﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Login
{
    public partial class Login2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "解忧注册";
            txtUsername1.Focus();
            lblInfo.Text = "";
        }

        protected void Btnzhuce_Click(object sender, EventArgs e)
        {
            lblInfo.Text = "注册成功，快来解忧杂货铺吧！";
            string strCn = "server=pc.hstc.cn;database=dhd2014112109;uid=2014112109;password=19950627";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();


                string strSql = "INSERT INTO Users1 (登录名, 密码, 邮箱,头像) VALUES   (N'" + this.txtUsername1.Text + "', N'" + this.txtPwd1.Text + "', N'" + this.txtQq.Text + "',N'" + (ddl1.SelectedIndex + 1).ToString() + "' )";
                SqlCommand cmd = new SqlCommand(strSql, cn);
                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.lblInfo.Text = "注册失败！";
                }
                else
                {
                    this.lblInfo.Text = "注册成功！";
                }
                Response.Write("<script>alert('恭喜，注册成功。单击“确定”返回登录页面。');location.href='Index.aspx';</script>");
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Image1.ImageUrl = "~\\头像\\" + (ddl1.SelectedIndex + 1) + ".jpg";
          
            
        }
        

    }
}